package com.linkgie.galaxyframework.utils;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 整数计数器；
 * <p>
 * 
 * 此实现不是线程安全的；
 * <p>
 * 在需要线程安全的场景时，推荐使用 {@link AtomicInteger } ；
 */
public class IntCounter {

    private int count;

    /**
     * @param initialValue
     */
    public IntCounter() {
        this.count = 0;
    }

    /**
     * @param initialValue
     */
    public IntCounter(int initialValue) {
        this.count = initialValue;
    }

    public void set(int value){
        this.count = value;
    }

    public int increase(){
        return ++count;
    }

    public int increase(int increment){
        count = count + increment;
        return count;
    }

    public int decrease(){
        return --count;
    }

    public int decrease(int decrement){
        count = count - decrement;
        return count;
    }

    public int value(){
        return count;
    }

}
